﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WebAuto
{
    public partial class TestDebugData : Form
    {
        private string _url = "";
        public TestDebugData()
        {
            InitializeComponent();
        }

        private void TestDebugData_Load(object sender, EventArgs e)
        {

        }

        public void SetDebugData(string data, string nodeParent)
        {
            
            if(nodeParent.ToLower().Contains("html"))
            {
                if (data.Contains("~"))
                {
                    _url = data.Split('~')[0];
                    richTextBox1.Text = data.Split('~')[1];

                }
                else
                {
                    richTextBox1.Text = data;
                }

                btnViewInBrowser.Enabled = true;
            }else
            {
                 btnViewInBrowser.Enabled = false;
                richTextBox1.Text = data;
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnViewInBrowser_Click(object sender, EventArgs e)
        {
            string fullHTML = "<!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
            fullHTML += "<html xmlns=\"http://www.w3.org/1999/xhtml\" >";
            fullHTML += richTextBox1.Text;
            fullHTML += "</html>";

            string tmpFileFullName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".html";
            using (StreamWriter sw = File.CreateText(tmpFileFullName))
            {
                sw.WriteLine(fullHTML);
                sw.Close();
            }

            ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
            startInfo.Arguments = tmpFileFullName;
            Process.Start(startInfo);

        }
    }
}
